﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SCABaselineCS.Tests.Reliability
{
    [TestClass]
    public class NullReference
    {
        [TestMethod]
        public void TestMethod1()
        {
            var winIdent = System.Threading.Thread.CurrentPrincipal.Identity as System.Security.Principal.WindowsIdentity;
            var canKerb = winIdent != null && winIdent.AuthenticationType.ToLower() == "Kerberos".ToLower();

            var useKerb = canKerb;

            Action DoNothing = () => { /* do nothing */ };
            if (useKerb)
                using (var impersonation = winIdent.Impersonate()) // winIdent cannot be null
                    DoNothing();
        }




        public void TestX()
        {
            var x = new object();

            var typedObj = x as System.OperatingSystem;
            if (typedObj == null)
                return;

            // reusing the same test, while less efficient, should still not result in a null reference
            (x as System.OperatingSystem).ToString();
        }


    } // class
} // namespace